<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MVCWeb.Models.User>>" %>

<%@ Register Src="~/Views/Menu/MainMenu.ascx" TagName="MainMenu" TagPrefix="mmuc" %>

<%@ Register Src="~/Views/Shared/LogOnUserControl.ascx" TagName="LogOnUserControl" TagPrefix="louc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Index</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script language="javascript" type="text/javascript">
        function ChangeStatus(id, name, status) {
            var s = 'active';
            if (status.toString() == "True") {
                s = 'deactive';
            }
            if (confirm("Are you sure that this user: " + name + " will be " + s + "?")) {
                // Perform change status.
                var action = '<%= Url.Action("ChangeStatus", "User") %>/' + id;
                var request = new Sys.Net.WebRequest();
                request.set_httpVerb("POST");
                request.set_url(action);
                request.add_completed(ChangeStatusCompleted);
                request.invoke();
            }
        }

        function ChangeStatusCompleted() {
            // Reload page  
            window.location.reload();
        }    
    </script>

    <louc:LogOnUserControl ID="LogOnUserControl1" runat="server" />
   <!-- BEGIN: MainMenu -->
    <mmuc:MainMenu ID="MainMenu1" runat="server" />
    <!-- END: MainMenu -->
    <br />
    <br />
    <h3 style="margin: .15in">
        Administration Users</h3>
    <table cellpadding="4" cellspacing="1" border="0" width="100%" class="DataTable">
        <tr>
            <th style="white-space: nowrap">
                User ID
            </th>
            <th style="white-space: nowrap">
                LogIn ID
            </th>
           <th style="white-space: nowrap">
                Status
            </th>
            <th style="white-space: nowrap">
                Action
            </th>
        </tr>
        <% foreach (var item in Model)
           { %>
        <tr>
            <td>
                <%= Html.Encode(item.UserId) %>
            </td>
            <td style="width: 100%">
                <%= Html.Encode(item.LogInID) %>
            </td>
            <td style="white-space: nowrap">
                <a onclick="ChangeStatus(<%=item.UserId%>, '<%=item.LogInID%>', '<%=item.Active%>')" href="JavaScript:void(0)">
                    <%
                        if (item.Active)
                        {
                    %>
                    Active
                    <%
                        }
                        else
                        {%>
                    Deactive
                    <%
                        }%>
                </a>
            </td>
            <td style="white-space: nowrap">
                <%= Html.ActionLink("Edit", "Edit", new {  id=item.UserId }) %>
                |
                <%= Html.ActionLink("Reset password", "ResetPassword", new { id=item.UserId })%>
            </td>
        </tr>
        <% } %>
    </table>
</asp:Content>
